﻿@page
@model Remotely.Server.Areas.Identity.Pages.Account.Manage.ServerLogsModel
@inject IDataService  DataService
@using Remotely.Shared.Enums
@{
    ViewData["Title"] = "Server Logs";
}
<h4>@ViewData["Title"]</h4>

@if (Model.IsAdmin)
{
    <div class="row mb-3">
        <div class="col-sm-4">
            <div class="mb-1">Delete Logs and Scripting History:</div>
            <form method="post" asp-page-handler="ClearLogs">
                <button class="btn btn-primary" type="submit">Delete All</button>
            </form>
        </div>
        <div class="col-sm-8 text-right">
            <div style="display:inline-block; text-align: left">
                <div class="mb-1">Download All:</div>
                <button class="btn btn-primary mr-3"
                        onclick="location.assign('/API/Commands/JSON')">
                    Scripting History
                </button>
                <button class="btn btn-primary"
                        onclick="location.assign('/API/ServerLogs/Download')">
                    Server Logs
                </button>
            </div>
        </div>
    </div>
    <form method="post" asp-page-handler="ApplyFilter">
        <div style="display:inline-block" class="mr-1">
            <strong>Type:</strong>
            <br />
            <select asp-for="Input.Type" asp-items="@Html.GetEnumSelectList<EventType>()">
                <option></option>
            </select>
        </div>
        <div style="display:inline-block" class="mr-1">
            <strong>From:</strong>
            <br />
            <input type="date" asp-for="Input.FromDate" />
        </div>
        <div style="display:inline-block" class="mr-1">
            <strong>To:</strong>
            <br />
            <input type="date" asp-for="Input.ToDate" />
        </div>
        <div style="display:inline-block" class="mr-1">
            <strong>Message:</strong>
            <br />
            <input type="text" asp-for="Input.Message" />
        </div>
        <button class="btn btn-primary" type="submit">Apply</button>
    </form>

    <table class="table table-hover table-striped">
        <thead>
            <tr>
                <th>Type</th>
                <th>Timestamp</th>
                <th>Message</th>
                <th>Source</th>
                <th>Stack Trace</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var eventLog in Model.EventLogs)
            {
                <tr>
                    <td>@eventLog.EventType</td>
                    <td>@eventLog.TimeStamp</td>
                    <td>@eventLog.Message</td>
                    <td>@eventLog.Source</td>
                    <td>@eventLog.StackTrace</td>
                </tr>
            }
        </tbody>
    </table>
}
else
{
    <h5 class="text-muted">Only organization administrators can view this page.</h5>
}